package codeRandomThoughts.Test701二叉搜索树中的插入操作;

import codeRandomThoughts.utils.TreeNode;

public class Solution {
    public TreeNode insertIntoBST(TreeNode root, int val) {
        if (root==null){
            return new TreeNode(val);
        }
        TreeNode node = root;
        TreeNode tem = root;
        while(true){
            tem = root;
            if (val>root.val){
                root = root.right;
                if (root==null){
                    tem.right = new TreeNode(val);
                    break;
                }
            }else if (val< root.val){
                root = root.left;
                if (root==null){
                    tem.left = new TreeNode(val);
                    break;
                }
            }
        }
        return node;
    }
}
